//*********************************************************
//
//    Copyright (c) Microsoft. All rights reserved.
//    This code is licensed under the Apache License, Version 2.0.
//    THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
//    ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
//    IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
//    PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//*********************************************************

namespace Microsoft.Research.ScientificWorkflow.TridentModel
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Collections.ObjectModel;
    using System.Collections.Specialized;

    [Serializable()]
    public abstract class BaseCompositeModel : BaseModel
    {
        public Collection<string> IterationValues { get; set; }

        public String SelectedValue { get; set; }

        public String NextSelectedValue { get; set; }

        /// <summary>
        /// The list of activity models contained in this subsection.
        /// </summary>
        private ObservableCollection<BaseModel> children = new ObservableCollection<BaseModel>();

        /// <summary>
        /// Gets the list of contained models.
        /// </summary>
        public ObservableCollection<BaseModel> Children
        {
            get
            {
                return this.children;
            }
        }

        /// <summary>
        /// The activity from which the subsection starts.
        /// </summary>
        public BaseModel StartModel
        {
            get
            {
                if (this.Children.Count > 0)
                {
                    return this.Children[0];
                }

                return null;
            }
        }

        /// <summary>
        /// The last activity in the subsection.
        /// </summary>
        public BaseModel EndModel
        {
            get
            {
                if (this.Children.Count > 0)
                {
                    return this.Children[this.Children.Count - 1];
                }

                return null;
            }
        }

        /// <summary>
        /// Fired when the child collection changes.
        /// </summary>
        public event EventHandler<NotifyCollectionChangedEventArgs> ChildrenCollectionChanged;

        /// <summary>
        /// Fired on collection changed of the children collection.
        /// </summary>
        /// <param name="sender">
        /// Children collection.
        /// </param>
        /// <param name="e">
        /// NotifyCollectionChangedEventArgs.
        /// </param>
        protected void OnChildCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            if (this.ChildrenCollectionChanged != null && this.ParentModel != null)
            {
                this.ParentModel.ChildrenCollectionChanged.Invoke(this, e);
            }
        }

        /// <summary>
        /// Raised the indexChangedEvent.
        /// </summary>
        public virtual void OnIndexChanged()
        {
            if (IndexChangedEvent != null)
            {
                IndexChangedEvent(this, null);
            }
        }

        /// <summary>
        /// This will be raised when index changed in combobox of iterative activity.
        /// </summary>
        public event EventHandler IndexChangedEvent;
    }

    /// <summary>
    /// This will hold the selected value and next to the selected value from iterative activity 
    /// in comboBox. This is required to find the range of Event Order.
    /// </summary>
    public struct SelectedValueStruct
    {
        public string SelectedValue { get; set; }

        public string NextSelectedValue { get; set; }
    }
}
